<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>店铺资料</title>
		<script src="../js/mui.min.js"></script>
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/iconfont.css" />
		<link rel="stylesheet" href="../css/style.css" />
		<link rel="stylesheet" href="../css/member.css" />
		<link rel="stylesheet" href="../css/picker.css" />
		<link rel="stylesheet" href="../css/poppicker.css" />
		<link rel="stylesheet" type="text/css" href="../css/datepicker3.css" />
		<script src="../plugin/crop/croppie.min.js"></script>
		<link rel="stylesheet" href="../css/font-awesome.min.css" />
		<link rel="stylesheet" href="../css/bootstrap.min.css" />

		<style type="text/css">
			.grzl_toux {
				position: relative;
			}
			/*#upload{opacity:0;filter:alpha(opacity=0);height: 95px; width: 100px;position: absolute;top: -80px;left: -40px;z-index: 9;}*/
			/*.btn_thumb{opacity:0;filter:alpha(opacity=0);height: 95px; width: 100px;position: absolute;top: -0px;left: -0px;z-index: 9;}*/
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title" id='d'>申请店铺</h1>
		</header>
		<div class="mui-content ">
			<div class="gerenzl_nr">
				<form class="mui-input-group gerenzl_group">
					<div class="gerenzl_top img-click">
						<div class="actions">
							<button class="file-btn">
				                <span><i class=" fa fa-plus"></i></span>
				                <input type="file" id="upload" value="选择图片文件" multiple />
				            </button>
							<div id="img_list" class="img_list">
							</div>
						</div>
						<div>店铺头像</div>
					</div>
					<div style="height:5px;background-color: #EFEFF4;"></div>
					<div class="mui-input-row ">
						<label>店铺名称</label>
						<input type="text" id="name" class="mui-input-group" placeholder="请填写店铺名称">
					</div>
					<!--<div class="mui-input-row">
						<label>真实姓名</label>
						<input type="text" id="real_name" class="mui-input-group" placeholder="请输入您的真实姓名">
					</div>-->
					<div class="mui-input-row">
						<label>店铺类型</label>
						<select class="mui-btn mui-btn-block" id="type">
							<option value="">请选择店铺归属</option>
							<option value="1">合作社</option>
							<option value="2">家庭农场</option>
							<option value="3">农庄</option>
							<option value="4">龙头企业</option>
						</select>
					</div>
					<div class="mui-input-row">
						<label>手机号码</label>
						<input type="text" id="mobile" class="mui-input-group" placeholder="请输入电话号码">
					</div>
					<div class="mui-input-row">
						<label>主要经营</label>
						<input type="text" id="main" class="mui-input-group" placeholder="">
					</div>
					<div class="mui-input-row">
						<label>地址</label>
						<input type="text" id="address"  class="mui-input-group" placeholder="请选择地区">
					</div>
				</form>
				<div class="gerzl_btn" id="btn" onclick="func1()">
					<a href="#" id="z">申请</a>
				</div>
			</div>
			<input type="hidden" id="member_id">
			<!--<input type="hidden" id="gui" value="1">-->
		</div>

	</body>

</html>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/bootstrap-datepicker.js"></script>
<script src="../js/layer/layer.min.js"></script>
<script src="../js/castapp.js"></script>
<script src="../js/app.js"></script>
<script src="../js/picker.js"></script>
<script src="../js/poppicker.js"></script>
<script src="../js/city.data-3.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script>
var member=JSON.parse(localStorage.getItem('member'));
		$(function() {
			dlpd();
		$('#upload').on('change', function() {
			
			readFile(this, "thumb", 1);
			$(".file-btn").hide();
		});
		//显示需要编辑得内容
		$.ajax({
			//type: 'post',
			url: APP.api_url + 'member/shopb',
			data: {
				id: member['id']
			},
			dataType:'jsonp',
			success: function(data) {
				if(data.code == 200) {
					var img=1;
					var innerHTML = '<div class="images-item">' +
					'	<span class="del">×</span>' +
					'	<img style="width: 80px;height: 80px; margin:0 auto;" src="' + APP.pic_url + data.data.pic + '"/>' +
					'	<input id="pic'+img+'" type="hidden" name="'+name+'" value="'+data.data.pic+'" />'+
					'	<input id="p" type="hidden" name="'+name+'1" value="'+img+'" />'+
					'</div>';
					$("#img_list").append(innerHTML);
					del_event();
					if($("#img_list").find('.images-item').size() >= length){
						$("#upload").parent(".file-btn").hide();
					}
					$("#name").val(data.data.company);
					$("#type").val(data.data.company_type);
					$("#mobile").val(data.data.phone);
					$("#address").val(data.data.address);
					$("#main").val(data.data.main_sell);
					if(data.data.status == 0){
						$("#z").html('申请中');
					document.getElementById('btn').onclick = function (){return false;};
					}else if(data.data.status == 1){
						$("#z").html('你已经是商家了');
						$("#d").html('店铺资料');
						document.getElementById('btn').onclick = function (){return false;};
					}	
				} else {
					console.log(data.msg);
				}
			}
		})
	});
	function func1(){
		var p=$("#p").val();
		if($("#upload").val() == '' && $("#pic"+p+"").val()==''){
			layer.msg('请选择图片', {icon: 1,time:1500,shade: 0.1})
			return false;
		}


		if($("#name").val() == ''){
			layer.msg('商家姓名不能为空', {icon: 1,time:1500,shade: 0.1})
			return false;
		}

		if($("#type").val() == ''){
			layer.msg('请选择商家归属', {icon: 1,time:1500,shade: 0.1})
			return false;
		}
		
		
		if($("#address").val() == ''){
			layer.msg('店铺地址不能为空', {icon: 1,time:1500,shade: 0.1})
			return false;
		}
		
		if($("#main").val() == ''){
			layer.msg('主要经营不能为空', {icon: 1,time:1500,shade: 0.1})
			return false;
		}
		if($("#mobile").val() == ''){
			layer.msg('电话号码不能为空', {icon: 1,time:1500,shade: 0.1})
			return false;
		}
		
		$.ajax({
			//type: 'post',
			url: APP.api_url + 'member/apply',
			dataType:'jsonp',
			data: {
				name: $("#name").val(),
				member_id: member['id'],
				address:$("#address").val(),
				main:$("#main").val(),
				type:$("#type").val(),
				pic:$("#pic"+p+"").val(),
				mobile:$("#mobile").val()
			},
			success: function(data) {
				layer.msg(data.msg, {icon: 1,time:1500,shade: 0.1}, function(index){
					localStorage.setItem('member', JSON.stringify(data.member));
                    window.location.href="../member/member_index.html";
                   });
			}
		});
	}
</script>
